package com.ypj.indusynergyems.dao.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ypj.indusynergyems.dao.entity.MenuEntity;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 菜单持久层
 */
@Mapper
public interface MenuMapper extends BaseMapper<MenuEntity> {

    @Select("select m.* from shoprole r left join permissions p on r.role_id = p.role_id " +
            " left join menu m on p.menu_id = m.menu_id where r.role_id = #{roleId}")
    List<MenuEntity> findUserMenuList(Integer roleId);

    @Select("select * from menu where menu_id = #{parentId}")
    MenuEntity findMenuByParentId(int parentId);

    //删除菜单-1.判断要删除的菜单，是否有角色拥有此菜单操作权限
    @Select("select * from permissions where menu_id = #{menuId} limit 1 ")
    String findRoleByMenuId(int menuId);

    //删除菜单-2.判断要删除的菜单，是否有子菜单
    @Select("select * from menu where parent_id = #{menuId} limit 1")
    MenuEntity findMenuChild(int menuId);

    //删除菜单-3
    @Delete("delete from menu where menu_id = #{menuId}")
    int deleteMenu(int menuId);
}
